<?
$pageName = "select";
include ROOT . '/view/common/student/header.php';
?>
<?
/**
 * @var CourseClass $courseClass
 * @var ClassTime $classTime
 * @var CourseSelection $courseSelection
 * @var $classTimes
 */
?>
	<div class="container">
	<form class="form-horizontal" role="form" method="post" action="/student/courseSelect/">
		<div class="page-header">
			<br /><br />
			<h2>
				<label>选课</label>
			</h2>
		</div>
		<div class="row" style="margin-bottom:30px;">
			<div class="col-xs-6"style="float: left">
				<h3>可选课程</h3>
				<table class="table table-striped">
					<thead>
					<tr>
						<th>课程名</th>
						<th>学分数</th>
						<th>学时</th>
						<th>授课老师</th>
						<th>上课时间</th>
						<th>操作</th>
					</tr>
					</thead>
					<tbody>
					<?
						foreach($courseClasses as $courseClass) {
							$rowSpan = count($classTimes[$courseClass->id]);
					?>
						<tr>
							<td rowspan="<?=$rowSpan?>"><?=$courseClass->course()->name?></td>
							<td rowspan="<?=$rowSpan?>"><?=$courseClass->course()->credit?></td>
							<td rowspan="<?=$rowSpan?>"><?=$courseClass->course()->period?></td>
							<td rowspan="<?=$rowSpan?>"><?=$courseClass->teacher()->name?></td>
							<td rowspan="<?=$rowSpan?>">
								<?
									foreach ($classTimes[$courseClass->id] as $classTime) echo "{$classTime->showDay()}&nbsp;&nbsp;&nbsp;{$classTime->startTime}-{$classTime->endTime}节<br/>";
								?>
							</td>
							<td rowspan="<?=$rowSpan?>"><a href="/student/add/?classCourseId=<?=$courseClass->id?>">选择</a></td>
						</tr>
						<?
							for ($i = 0; $i < $rowSpan - 1; $i++) echo "<tr></tr>";
							if ($i % 2 != 0) echo "<tr></tr>"; //correct the color of the next row
						?>
					<?}?>
					</tbody>
				</table>
			</div>
			<div class="col-xs-6"style="float: right">
				<h3>已选课程</h3>
				<table class="table table-striped">
					<thead>
					<tr>
						<th>课程名</th>
						<th>学分数</th>
						<th>学时</th>
						<th>授课老师</th>
						<th>上课时间</th>
						<th>操作</th>
					</tr>
					</thead>
					<tbody>
					<?
						foreach($courseSelections as $courseSelection) {
							$rowSpan = count($classTimes[$courseSelection->courseClass()->id]);
					?>
						<tr>
							<td rowspan="<?=$rowSpan?>"><?=CourseClass::load($courseSelection->courseClassId)->course()->name?></td>
							<td rowspan="<?=$rowSpan?>"><?=CourseClass::load($courseSelection->courseClassId)->course()->credit?></td>
							<td rowspan="<?=$rowSpan?>"><?=CourseClass::load($courseSelection->courseClassId)->course()->period?></td>
							<td rowspan="<?=$rowSpan?>"><?=CourseClass::load($courseSelection->courseClassId)->teacher()->name?></td>
							<td rowspan="<?=$rowSpan?>">
								<?
									foreach ($classTimes[$courseSelection->courseClass()->id] as $classTime) echo "{$classTime->showDay()}&nbsp;&nbsp;&nbsp;{$classTime->startTime}-{$classTime->endTime}节<br/>";
								?>
							</td>
							<td rowspan="<?=$rowSpan?>"><a href="/student/remove/?courseSelectionId=<?=$courseSelection->id?>">取消</a></td>
						</tr>
						<?
							for ($i = 0; $i < $rowSpan - 1; $i++) echo "<tr></tr>";
							if ($i % 2 != 0) echo "<tr></tr>"; //correct the color of the next row
						?>
					<?}?>
					</tbody>
				</table>
			</div>
		</div>
	</form>
		<!-- .row -->
		<center><div class="subpages row"><ul class="pagination pagination-sm"></ul></div></center>
	</div>
<? include ROOT . '/view/common/footer.php'; ?>